package com.matchmealpha;

import java.util.ArrayList;

import android.app.ActivityGroup;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

public class FriendsListGroup extends ActivityGroup {
	public static FriendsListGroup friendsListGroup;
	private ArrayList<View> friendsListHistory;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.friendsListHistory = new ArrayList<View>();
		friendsListGroup = this;

		// Start the root activity within the group and get its view
		View view = getLocalActivityManager().startActivity(
				"FriendsListActivity",
				new Intent(this, FriendsListActivity.class)
						.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
				.getDecorView();

		// Replace the view of this ActivityGroup
		replaceView(view);

	}

	public void replaceView(View v) {
		// Adds the old one to history
		friendsListHistory.add(v);
		// Changes this Groups View to the new View.
		setContentView(v);
	}

	public void back() {
		if (friendsListHistory.size() > 0) {
			friendsListHistory.remove(friendsListHistory.size() - 1);
			setContentView(friendsListHistory.get(friendsListHistory.size() - 1));
		} else {
			finish();
		}
	}
	
	public ArrayList<View> getHistory(){
		return friendsListHistory;
	}

	@Override
	public void onBackPressed() {
		FriendsListGroup.friendsListGroup.back();
		return;
	}
}
